package karstenTest;

import java.util.ArrayList;
import java.util.HashMap;

import org.jgrapht.Graph;
import org.jgrapht.graph.DefaultWeightedEdge;

import a1_p04_jw_kw.graph.GraphCreater;
import a1_p04_jw_kw.graph.GraphParser;
import a1_p04_jw_kw.struct.GraphSetup;
import a1_p04_jw_kw.struct.GraphTransition;
import a1_p04_jw_kw.struct.Node;
import a4_p04_jw_kw.euler.Hierholzer;
import a4_p04_jw_kw.searchalgo.HolzerDFS;

public class HierholzerTest {
	Graph<Node, DefaultWeightedEdge> g;

	Graph<Node, DefaultWeightedEdge> wikiGraph;

	
	public HierholzerTest(Graph<Node, DefaultWeightedEdge> g) {
		this.g = g;
	}

	public void dfsTest(){
		HolzerDFS dfs = new HolzerDFS(g);
		dfs.startSearch("1");
		System.out.println(dfs.getWay());
	}
	
	public void eulerTest(){
		
	}
	
	public void createWikiGraph() {
		String[] nodes = new String[] { "1", "2", "3", "4", "5", "6", "7", "8",
				"9" };
		HashMap<String, Node> vertixes = new HashMap<String, Node>();

		for (String nodeName : nodes) {
			Node newNode = new Node(nodeName);
			vertixes.put(nodeName, newNode);
		}

		// setup Transitions
		ArrayList<GraphTransition> transitions = new ArrayList<GraphTransition>();

		ArrayList<String[]> transNames = new ArrayList<String[]>();
		transNames.add(new String[] { "1", "2" });
		transNames.add(new String[] { "1", "3" });
		transNames.add(new String[] { "1", "7" });
		transNames.add(new String[] { "1", "8" });

		transNames.add(new String[] { "2", "1" });
		transNames.add(new String[] { "2", "3" });

		transNames.add(new String[] { "3", "4" });
		transNames.add(new String[] { "3", "7" });

		transNames.add(new String[] { "4", "5" });
		transNames.add(new String[] { "4", "7" });
		transNames.add(new String[] { "4", "9" });

		transNames.add(new String[] { "5", "9" });

		transNames.add(new String[] { "6", "7" });
		transNames.add(new String[] { "6", "9" });
		transNames.add(new String[] { "7", "8" });
		transNames.add(new String[] { "7", "9" });

		transNames.add(new String[] { "3", "1" });
		transNames.add(new String[] { "3", "2" });
		transNames.add(new String[] { "4", "3" });
		transNames.add(new String[] { "5", "4" });
		transNames.add(new String[] { "7", "1" });
		transNames.add(new String[] { "7", "3" });
		transNames.add(new String[] { "7", "4" });
		transNames.add(new String[] { "7", "6" });
		transNames.add(new String[] { "8", "1" });
		transNames.add(new String[] { "8", "7" });
		transNames.add(new String[] { "9", "4" });
		transNames.add(new String[] { "9", "5" });
		transNames.add(new String[] { "9", "6" });
		transNames.add(new String[] { "9", "7" });

		// setup graph
		for (String[] nodeTrans : transNames) {
			transitions.add(new GraphTransition(vertixes.get(nodeTrans[0]),
					vertixes.get(nodeTrans[1])));
		}
		GraphSetup gs = new GraphSetup(true, false, false, false, transitions);
		GraphCreater gc = new GraphCreater(gs);
		gc.createGraph();
		wikiGraph = gc.getGraph();
	}
	
	public static void main(String[] args) {
		Graph<Node, DefaultWeightedEdge> gCopy;

		Hierholzer holzer = new Hierholzer();
//		holzer.createWikiGraph();
		
		GraphParser gp = new GraphParser("hierholzer.gka");

		// create the graph as JGraphT graph
		GraphCreater gc = new GraphCreater(gp.getGraphSetup());
		gc.createGraph();
		gCopy = gc.getGraph();
		
		
//		HierholzerTest test = new HierholzerTest(holzer.getWikiGraph());
//		HierholzerTest test = new HierholzerTest(holzer.getTestGraph());
//		test.dfsTest();
		
		holzer.createEulerTour("1", holzer.createHolzerGKA());
		System.out.println(holzer.getEulerTour());
	}

}
